/**create at 9-1-17 */

loginController.$inject = ['$scope','$location','loginService'];

function loginController($scope,$location,loginService){
    var vm = this;
    vm.login = function(){
        var user = {
            username:vm.username,
            password:vm.password
        }
        if(vm.username != null && vm.password != null){
            loginService.login(user,function(err,result){
            if(err){console.log('login error')}
            else{
                console.log('============>'+ result.username);
                if(result.username != null){
                    //add customer to session
                    sessionStorage.setItem("customer",JSON.stringify(result));
                    let shoppingCart = [];
                    sessionStorage.setItem("shoppingCart", JSON.stringify(shoppingCart));
                    $location.path('/');
                }else{
                    vm.massage='用户名或密码错误！'
                    //$location.path('/login');
                }
               
            }
        });
        }
        
    }
}

module.exports = loginController;